import types from '../types.js'
import axios from 'axios'
const state = {
    //第三步，拿到改变后的值
    seller:{},
    detailShow:false
}

const getters = {
    seller(state){
        return state.seller;
    },
    detailShow(state){
        return state.detailShow;
    }
}

const actions = {
    getSeller({commit,state}){
        axios.get('api/seller').then(res => {
            // console.log(res);
            if(res.data.errno==0){
                commit(types.GET_SELLER,res.data.data)
            }
        })
    },
    //第一步，提交突变
    showDetail({commit}){
        commit(types.SHOW_DETAIL)
    },
    hideDetail({commit}){
        commit(types.HIDE_DETAIL)
    }
}

const mutations = {
    [types.GET_SELLER](state,data){
        state.seller = data;
    },
    //第二步，改变值
    [types.SHOW_DETAIL](state){
        state.detailShow = true;
    },
    [types.HIDE_DETAIL](state){
        state.detailShow = false;
    }
}

export default {
    state,
    getters,
    actions,
    mutations
}